package com.mianyang.zhangsan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mianyang.zhangsan.common.base.BaseController;
import com.mianyang.zhangsan.common.base.R;
import com.mianyang.zhangsan.model.entity.SecTask;
import com.mianyang.zhangsan.service.SecTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jiangjr
 * @date 2022-11-25
 */
@RestController
@RequestMapping("/task")
public class SecQuartzTaskController extends BaseController {
    @Autowired
    private SecTaskService taskService;

    @GetMapping("/query")
    public R queryTask(SecTask task,
                       @RequestParam(value = "current", defaultValue = "1") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<SecTask> taskPages = taskService.selectTaskByPage(task, current, pageSize);
        return success("tasks", taskPages);
    }

    @PostMapping("/add")
    public R addTask(@RequestBody SecTask task) {
        taskService.schedulerAndSave(task);
        return success();
    }

    @DeleteMapping("/delete/{taskId}")
    public R deleteTask(@PathVariable("taskId") Long taskId) {
        taskService.removeById(taskId);
        return success();
    }

    @PutMapping("/edit")
    public R editTask(@RequestBody SecTask task) {
        taskService.updateById(task);
        return success();
    }
}
